#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":platform:usb"
    module.description = "Universal Serial Bus (USB)"

def prepare(module, options):
    device = options[":target"]
    if not (device.has_driver("usb:sam*") or
            device.has_driver("udp:sam*")):
        return False

    module.depends(
        ":architecture:interrupt",
        ":cmsis:device",
        ":platform:gpio",
        ":platform:clock")

    return True

def build(env):
    device = env[":target"]
    properties = device.properties
    properties["target"] = device.identifier
    env.substitutions = properties
    env.outbasepath = "modm/src/modm/platform/usb"
    env.template("usb.hpp.in")
    if env.has_module(":tinyusb:device:cdc"):
        env.copy(repopath("ext/hathach/uart.hpp"), "uart.hpp")

